package com.sdkj.dspservice.modules.report.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sdkj.dspservice.common.base.entity.DataEntity;
import com.sdkj.dspservice.common.utils.StringUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * 表配置实体
 * @author tm
 */
@Slf4j
@Data
@TableName(value = "report_table_config")
public class TableConfig extends DataEntity<TableConfig> {

    /**
     * 名称
     */
    @NotBlank(message = "名称不能为空")
    private String name;
    /**
     * 数据源
     */
    @NotNull(message = "数据源不能为空")
    private String sourceId;
    /**
     * 表名
     */
    @NotBlank(message = "表名不能为空")
    private String tableName;

    /**
     * 字段列表
     */
    @TableField(exist = false)
    private List<TableConfigColumn> columnList = new ArrayList<>();
    @TableField(exist = false)
    private Source source;

    public TableConfig() {
    }

    public TableConfig(String id) {
        super(id);
    }

    @Override
    public QueryWrapper<TableConfig> makeQueryWrapper(QueryWrapper<TableConfig> queryWrapper) {
        if(StringUtils.isNotBlank(name)){
            queryWrapper.like("a.name", name);
        }
        return super.makeQueryWrapper(queryWrapper);
    }
}